package simpleGeom;

import java.awt.geom.Line2D;

import processing.core.PGraphics;

public class Line implements HasLine2D{
public float x1;
public float y1;
public float x2;
public float y2;
int id;

public Line(float x1,float y1,float x2,float y2){
	this.x1=x1;
	this.y1=y1;
	this.x2=x2;
	this.y2=y2;
}
public float getX1() {
	return x1;
}
public void setX1(float x1) {
	this.x1 = x1;
}
public float getY1() {
	return y1;
}
public void setY1(float y1) {
	this.y1 = y1;
}
public float getX2() {
	return x2;
}
public void setX2(float x2) {
	this.x2 = x2;
}
public float getY2() {
	return y2;
}
public void setY2(float y2) {
	this.y2 = y2;
}
public float dx(){
	return x2-x1;
}
public float dy(){
return y2-y1;
	
}
public Bounds2D bounds(){
	Bounds2D b2d=new Bounds2D();
	b2d.addPos2D(x1, y1);
	b2d.addPos2D(x2, y2);
	return b2d;
}

public int getId() {
	return id;
}
public void setId(int id) {
	this.id = id;
}
public static Line getOffsetLine(HasPos2D p1, HasPos2D p2,
		float offset) {
	Vec2D v=Vec2D.sub(p2, p1);
	v.setLength(offset);
	v.rot90();
	Vec2D p1Offset = Vec2D.add(p1, v);
	Vec2D p2Offset = Vec2D.add(p2, v);
	return new Line(p1Offset.getX(),p1Offset.getY(), p2Offset.getX(),p2Offset.getY());
}
public  Line getOffsetLine(
		float offset) {
	return getOffsetLine( new Vec2D(x1,y1),new Vec2D(x2,y2),offset);
}
public void display(PGraphics pg){
	pg.line(x1, y1, x2, y2);
}
public float getCenterX(){
	return (x2-x1)*0.5f+x1;
}
public float getCenterY(){
	return (y2-y1)*0.5f+y1;
}
public float getLength(){
	float dX=x2-x1;
	float dY=y2-y1;
	return (float)Math.sqrt(dX*dX+dY*dY);
}
public float getAngle(){
	float dX=x2-x1;
	float dY=y2-y1;
	return Vec2D.getAngle(dX,dY);
}
}
